#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project  : ecshop
# @File     : page_backend_install_and_uninstall_distribution.py
# @Author   : WanLiWei
# @Time     : 2021/7/3 15:58
from time import sleep


class PageBackendInstallAndUninstallDistribution():
    def __init__(self, driver):
        self.driver = driver

    def test_click_systeml(self):
        # 进入id为menu-frame的frame
        self.driver.switch_to.frame('menu-frame')
        # 点击系统管理
        self.driver.find_element_by_xpath('//ul[@id="menu-ul"]/li[9]').click()

    def test_click_distribution_mode(self):
        # 点击配送方式
        self.driver.find_element_by_xpath('//ul[@id="menu-ul"]/li[9]/ul/li[4]/a').click()
        # 退出frame
        self.driver.switch_to.default_content()
        # 进入id为main-frame的frame

    def test_click_install(self):
        self.driver.switch_to.frame('main-frame')
        self.driver.find_element_by_xpath('//div[@id="listDiv"]/table/tbody/tr[2]/td[8]/a').click()
        sleep(3)

    def test_distribution_name(self):
        # 配送区域名称
        self.driver.find_element_by_xpath('/html/body/div[1]/form/fieldset[1]/table/tbody/tr[1]/td[2]/input').send_keys(
            "四川")


    def test_country(self):
        #
        self.driver.find_element_by_xpath('//select[@id="selCountries"]/option').click()

    def test_province(self):
        # 省份
        self.driver.find_element_by_xpath('//select[@id="selProvinces"]/option[26]').click()

    def test_city(self):
        # 城市
        self.driver.find_element_by_xpath('//select[@id="selCities"]/option[2]').click()

    def test_area(self):
        # 区/县
        self.driver.find_element_by_xpath('//select[@id="selDistricts"]/option[3]').click()

    def test_click_add(self):
        # 点击添加按钮
        self.driver.find_element_by_xpath(
            '/html/body/div[1]/form/fieldset[2]/table/tbody/tr[2]/td/span[5]/input').click()

    def test_click_confirm(self):
        # 弹框点确定
        self.driver.find_element_by_xpath('/html/body/div[1]/form/table/tbody/tr/td/input[1]').click()
        # 退出frame
        self.driver.switch_to.default_content()

    def test_click_uninstall(self):
        self.driver.switch_to.frame('main-frame')
        # 点击货到付款卸载按钮
        self.driver.find_element_by_xpath('//div[@id="listDiv"]/table/tbody/tr[2]/td[8]/a[1]').click()
        # 弹框点确定

    def test_click_alent_confirm(self):
        self.driver.switch_to.alert.accept()
        self.driver.switch_to.default_content()

    def test_install_distribution(self):
        self.test_click_systeml()
        self.test_click_distribution_mode()
        self.test_click_install()
        self.test_distribution_name()
        self.test_country()
        self.test_province()
        self.test_city()
        self.test_area()
        self.test_click_add()
        self.test_click_confirm()

    def test_uninstall_distribution(self):
        self.test_click_systeml()
        self.test_click_distribution_mode()
        self.test_click_uninstall()
        self.test_click_alent_confirm()
